from mvg import Glue

class AlbumGlue(Glue):

    def glue_the_model(self, m):
        self.model = m
        m.count.register(self._count)
        m.start()

    def _count(self, data):
        self.view.count.value = data

    def glue_the_view(self, v):
        self.view = v
        v.new_album.register(self._new_album)
        v.save.register(self._save)
        v.cancel.register(self._cancel)
        v.order.register(self._order)
        self._order('Z')
        
    def _new_album(self, data):
        v = self.view
        print 'new album', data, v.artist.get(), v.album.get()

    def _save(self, data):
        print 'save', data
        if not hasattr(self, 'model'):
            return
        self.model.append(*data)

    def _cancel(self, data):
        print 'cancel', data

    def _order(self, data):
        v = self.view
        if data.startswith('A'):
            v.order.set('Z->A')
        else:
            v.order.set('A->Z')

from album_model import AlbumModel
from album_view import AlbumView

AlbumGlue(AlbumModel(), AlbumView())
